<script lang="ts">
import { defineComponent,onMounted,ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '../stores/class'
import { viewCount, filters, vidotime } from '../hooks/filters'
import { getimage } from '../hooks/image'
import { storeToRefs } from 'pinia';

export default defineComponent({
  setup() {
    let router: any = useRouter()
    let back: any = (): any => {
      router.back()
    }
    let findClass: any = (): any => {
      router.push({
        path:'/class'
      })
    };
    let clickMyClass = (groupId:number,price:string) => {
      router.push({
        path: '/classDes',
        query: {
          groupId,
          price,
        }
      })
    }
    const store = useStore()

    // let myclass = store.payClass;
    // const { payClass, CollectClassList } = storeToRefs(store)
    // let CollectClassList = store.CollectClassList;
    // console.log("CollectClassList=>", CollectClassList);
    // console.log(payClass);
    let payClassJson: any = ref(window.localStorage.getItem("payClass"));
    let payClass = ref(JSON.parse(payClassJson.value) || []);
    let CollectClassListJson: any = ref(window.localStorage.getItem("CollectClassList"));
    let CollectClassList :any= ref(JSON.parse(CollectClassListJson.value) || []);
    onMounted(() => {
      payClass.value= payClass.value.filter((item:any)=>{
        return item.payment==1;
      })
    })
    return {
      back,
      findClass,
      payClass,
      getimage,
      viewCount,
      clickMyClass,
      CollectClassList
    }
  }
})
</script>
<template>
  <div>
    <div class="desbar">
      <span class="iconfont icon-xiangzuojiantou" @click="back"> </span>
      <h2>我的课程</h2>
    </div>
    <div class="tabs">
      <van-tabs animated swipeable color="#df2e22" line-width="23">
        <van-tab title="我报名的">
          <div  class=" tag" v-if="payClass.length==0">
            还没有学习课程...
            <p @click="findClass">发现课程</p>
          </div>
          <div class="myPayClass" v-else>
            <ul>
              <li v-for="item in payClass" :key="item.groupId" @click="clickMyClass(item.groupId,item.price)">
                <div
                  class="classimg"
                  :style="
                    'background: url(' + getimage(item.data.avatar) + ') no-repeat 50% 50%/100%'
                  "
                >
                  <!-- // <img :src="getimage(item.avatar)" alt="" /> -->
                </div>
                <div class="list-right">
                  <div class="smalltag" v-if="item.data.categoryName">
                    <span>{{ item.data.categoryName }}</span>
                  </div>
                  <span>{{ item.data.groupName }}</span>
                  <div class="list-count one-text-cut">
                    {{ item.data.ownerInfo.nickName }} | {{ item.data.lessonCount }}课时 |
                    {{ viewCount(item.data.memberCount) }}人在学习
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab title="我收藏的">
          <div  class=" tag" v-if="CollectClassList.length==0">
            还没有收藏课程...
            <p @click="findClass">发现课程</p>
          </div>
          <div class="myPayClass" v-else>
            <ul>
              <li v-for="item in CollectClassList" :key="item.groupId" @click="clickMyClass(item.data.groupId,item.price)">
                <div
                  class="classimg"
                  :style="
                    'background: url(' + getimage(item.data.avatar) + ') no-repeat 50% 50%/100%'
                  "
                >
                  <!-- // <img :src="getimage(item.data.avatar)" alt="" /> -->
                </div>
                <div class="list-right">
                  <div class="smalltag" v-if="item.data.categoryName">
                    <span>{{ item.data.categoryName }}</span>
                  </div>
                  <span>{{ item.data.groupName }}</span>
                  <div class="list-count one-text-cut">
                    {{ item.data.ownerInfo.nickName }} | {{ item.data.lessonCount }}课时 |
                    {{ viewCount(item.data.memberCount) }}人在学习
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.desbar {
  display: flex;
  line-height: 44px;
  padding: 0 10px;
  position: sticky;
  z-index: 10;
  top: 0;
  span {
    font-size: 20px;
    font-weight: 600;
  }
  h2 {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;

    // margin-left: 50px;
  }
}
.tabs {
  .tag {
    width: 100%;
    height: 200px;
    text-align: center;
    line-height: 200px;
    color: #9da1a8;
    font-size: 14px;
    position: relative;
    p {
      background-color: #e54c3c;
      color: #fff;
      height: 36px;
      width: 170px;
      text-align: center;
      line-height: 36px;
      position: absolute;
      border-radius: 20px;
      font-size: 16px;
      top: 130px;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}
.myPayClass {
  padding: 0 15px;
  margin-top: 10px;
  ul {
    li {
      display: flex;
      align-items: center;
      margin-bottom: 15px;
      .classimg {
        width: 140px;
        height: 90px;
        flex-shrink: 0;
        img {
          width: 146px;
          height: 90px;
        }
      }
      .list-right {
        margin-left: 10px;
        
        .smalltag {
          display: inline-block;
          background: #464d5c;
          padding: 1px 2px;
          line-height: 15px;
          margin-right: 2.5px;
          color: #fff;
          font-size: 12px;
          span {
            display: inline-block;
            transform: scale(0.9);
          }
        }
        & > span {
          font-size: 14px;
          
        }
        .list-count {
          color: #687583;
          font-size: 12px;
          line-height: 30px;
          width: 165px;
          margin-top: 10px;
        }
        .price {
          color: #ff3271;
          font-weight: 700;
          font-size: 14px;
        }
      }
    }
  }
}
</style>